package net.awpspace.mobile.management.note;


public class Convert {
	public static Note parserNote(String str) {
		Note note;
		String name;
		String content;
		String place;
		int ngay;
		int thang;
		int nam;
		boolean on_alarm;
		int gio;
		int phut;
		boolean cn;
		boolean t2;
		boolean t3;
		boolean t4;
		boolean t5;
		boolean t6;
		boolean t7;

		String path = "..|..";
		int index;

		index = str.indexOf(path);
		name = str.substring(0, index);
		str = str.substring(index + 5);

		index = str.indexOf(path);
		content = str.substring(0, index);
		str = str.substring(index + 5);

		index = str.indexOf(path);
		place = str.substring(0, index);
		str = str.substring(index + 5);

		index = str.indexOf(path);
		ngay = Integer.parseInt(str.substring(0, index));
		str = str.substring(index + 5);

		index = str.indexOf(path);
		thang = Integer.parseInt(str.substring(0, index));
		str = str.substring(index + 5);

		index = str.indexOf(path);
		nam = Integer.parseInt(str.substring(0, index));
		str = str.substring(index + 5);

		index = str.indexOf(path);
		on_alarm = checkBoolean(str.substring(0, index));

		str = str.substring(index + 5);

		index = str.indexOf(path);
		gio = Integer.parseInt(str.substring(0, index));
		str = str.substring(index + 5);

		index = str.indexOf(path);
		phut = Integer.parseInt(str.substring(0, index));
		str = str.substring(index + 5);

		index = str.indexOf(path);
		cn = checkBoolean((str.substring(0, index)));
		str = str.substring(index + 5);

		index = str.indexOf(path);
		t2 = checkBoolean((str.substring(0, index)));
		str = str.substring(index + 5);

		index = str.indexOf(path);
		t3 = checkBoolean((str.substring(0, index)));
		str = str.substring(index + 5);

		index = str.indexOf(path);
		t4 = checkBoolean((str.substring(0, index)));
		str = str.substring(index + 5);

		index = str.indexOf(path);
		t5 = checkBoolean((str.substring(0, index)));
		str = str.substring(index + 5);

		index = str.indexOf(path);
		t6 = checkBoolean((str.substring(0, index)));
		str = str.substring(index + 5);

		t7 = checkBoolean(str);
		if (on_alarm) {
			note = new Note(name, content, place, ngay, thang, nam, on_alarm,
					gio, phut, cn, t2, t3, t4, t5, t6, t7);
		} else {
			note = new Note(name, content, place, ngay, thang, nam, on_alarm);
		}

		return note;
	}

	public static String parserString(Note note) {
		String str = "";
		String path = "..|..";

		str = note.getName() + path + note.getContent() + path
				+ note.getPlace() + path + note.getNgay() + path
				+ note.getThang() + path + note.getNam() + path
				+ note.isAlarm() + path + note.getGio()+path+note.getPhut()+path + note.isCn() + path + note.isT2()
				+ path + note.isT3() + path + note.isT4() + path + note.isT5()
				+ path + note.isT6() + path + note.isT7();

		return str;
	}

	public static boolean checkBoolean(String s) {
		if (s.equals("true"))
			return true;
		else
			return false;
	}
}
